<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page language="java" import="com.supereye.platform.web.sys.model.SysUser" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>修改密码</title>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<link href="../../pages/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="../../pages/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
<link rel="stylesheet" href="../../pages/bootstrap/animate.min.css">
<link rel="stylesheet" href="../../pages/common/styles/common.css">
<script src="../../pages/jquery/jquery-1.12.4.min.js"></script>
<script src="../../pages/bootstrap/js/bootstrap.min.js">
</script><script src="../../pages/common/js/common.js"></script>

<style>
	
	.firstboundary{
		width:1200px;
		height:600px;
		margin:0 auto;
		background-repeat:no-repeat;
		background-position:center;
	}
	
	.titles{
		font-size: 30px;
		color: #03A9f4;
		padding-top: 30px;
	}
	
	.infoLable{
		margin-left:410px;
		font-size: 14px;
		padding-top: 5px;
		padding-bottom: 5px;
	}
	
	.infoInput{
		width:300px;
		height:40px;
		margin-top:20px;
		margin-left: 8px;
		padding-top: 5px;
		padding-bottom: 5px;
	}
	
	.lablename{
		height:40px;
		line-height:40px;
		font-size: 16px;
		font-weight:normal;
		position: relative;
		top: 2px;
		margin-left: 10px;
	}
	
	.errortext{
		font-size:18px;
		color:#000000;
		position: relative;
		margin-left: 0px;	
		color: rgb(235,97,0);
	}
	
	.errorimg{
		margin-left: 10px;	
		font-family:微软雅黑; 
		position: relative;
		bottom: 4px;
	}
	

	#newpassword2Lable{
		margin-left: 395px;
	}
	
	.managerText{
		font-size: 24px;
		color: #03a9f4;
		font-weight:normal;
	}
	
	.nameDiv{
		margin-top: 10px;
	}
</style>

</head>
<body style="overflow:hidden">
   <div class="firstboundary">
	<div id="formtext">
		<form align="left">
		
			<div style="text-align: center; margin-top: 20px;">
				<span id="titles" class="titles">修改密码</span>
			</div>
		
			<div style="display: none;">
				<input id="id" type="text" value=""/>
			</div>
		
			<div style="text-align: center;margin-top: 10px;">
				<img id="" src="../../pages/images/passwordpage.png";class="errorimg"/>
				<br/>
				<label id="managerText" class="managerText">管理员</label>
			</div>
		
		
			<div id="" class="nameDiv">
				<label id="accountLable" class="infoLable inline">姓&nbsp;&nbsp;&nbsp;名</label>
				<label id="account" class="lablename"></label>
			</div>
			
			<div >
				<label id="oldPasswordLable" class="infoLable inline">旧密码</label>
				<input id="oldpassword"  class="form-control inline infoInput"  type="text" placeholder="请输入旧密码"/>
				<img id="errorimg1" class="errorimg" src="../../pages/images/logo/error.png";width="17" height="17"/>
				<text id="errortext1" class="errortext">旧密码不能为空</text>
			</div>
			
			<div >
				<label id="newpassword1Lable" class="infoLable">新密码</label>
				<input id="newpassword1"  class="form-control inline infoInput" type="text" placeholder="请输入新密码"/>
				<img id="errorimg2" class="errorimg" src="../../pages/images/logo/error.png";width="17" height="17" />
				<text id="errortext2" class="errortext">新密码不能为空</text>
			</div>
			
			<div >
				<label id="newpassword2Lable" class="infoLable">确认密码</label>
				<input id="newpassword2" class="form-control inline infoInput" type="text" placeholder="请输入新密码确认"/>
				<img id="errorimg3" class="errorimg" src="../../pages/images/logo/error.png";width="17" height="17"/>
				<text id="errortext3" class="errortext">确认密码不能为空</text>
			</div>
				
			<div style="text-align: center;margin-top: 20px;">
				<a class="a-btn-submit" onclick="savepassword()" >提 &nbsp;&nbsp;交</a>
				<a class="a-btn-cancel" onclick="resetpassword()" style="margin-left: 50px;">重 &nbsp;&nbsp;置</a>
			</div>
		</form>
	</div>
</div>
 </body>
<script type="text/javascript">

$(document).ready(function() {
	$("#id").val(<%=((SysUser)request.getSession().getAttribute("loginUser")).getId()%>);
	$("#account").html("<%=((SysUser)request.getSession().getAttribute("loginUser")).getName()%>");
	$(".errortext").hide();
	$(".errorimg").hide();
});
	
	
function savepassword(){
	var oldpassword = $("#oldpassword").val();
	var newpassword1 = $("#newpassword1").val();
	var newpassword2 = $("#newpassword2").val();
	$(".errortext").hide();
	$(".errorimg").hide();
	
	if(oldpassword == null||oldpassword == ""){
		$("#errorimg1").show();
		$("#errortext1").show();
		$("#oldpassword").focus();
	}else if(newpassword1 == null||newpassword1 == ""){
		$("#errorimg2").show();
		$("#errortext2").show();
		$("#newpassword1").focus();
	}else if(newpassword2 == null||newpassword2 == ""){
		$("#errortext3").html("确认密码不能为空");
		$("#errorimg3").show();
		$("#errortext3").show();
		$("#newpassword2").focus();
	}else if(newpassword1 != newpassword2){
		$("#errortext3").html("两次密码输入不一致");
		$("#errorimg3").show();
		$("#errortext3").show();
		$("#newpassword2").focus();
	}else{
		$.ajax({
	        type: "post",
	        dataType: "json",
	        url: '${ctx}/sysUser/updatePassword',
	        data:{
	        	password:oldpassword,
	        	newpassword:newpassword1
	        },
	        success: function (data) {
	        	if(data.status=="1"){
	        		$.MsgBox.Alert("提示",data.msg,function(){
	        			$.ajax({
	        		        type: "post",
	        		        dataType: "json",
	        		        url: '${ctx}/login/loginout',
	        		        data:{
	        		        },
	        		        success: function (data) {
	        		        	if(data.status=="1"){
	        		        		window.parent.location.href="../../login.html";
	        		        	}
	        		        },
	        				error:function(){
	        					$("#errortext3").html("链接超时!");
	        	        		$("#errorimg3").show();
	        	        		$("#errortext3").show();
	        				}
	        		    });
	        		});
	       
	        	}else{
	        		$("#errortext3").html(data.msg);
	        		$("#errorimg3").show();
	        		$("#errortext3").show();
	        	}
	        	
	        },
			error:function(){
				$("#errortext3").html("链接超时!");
        		$("#errorimg3").show();
        		$("#errortext3").show();
			}
	    });
	} 
}

function resetpassword(){
	$("input").val("");
	$("#oldpassword").focus();
}
	
</script>
</html>